import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df1 = pd.read_csv('mtcars.csv')
print(df1.head())
print(df1.shape)
#plt.style.use('fivethirtyeight')
plt.style.use('classic')
x1 = np.arange(0,25)
#print(x1)
y1 = x1 * 2
#print(y1)
y2 = x1 ** 2
plt.plot(x1,y1, color='yellow', linestyle='dashed', marker='o', label='linear plot')
plt.plot(x1,y2, color='blue', linestyle='solid', marker='>', label='expo plot')
plt.plot([1]*600,list(range(600)), color='#ff00ff', linestyle='dotted', marker='>', label='expo plot')
plt.xlabel('x_label')
plt.ylabel('y_label')
plt.title("first plot")
plt.legend(loc=0)
plt.savefig("myfirstplot.png")
plt.show()
plt.figure(figsize=(10,8),dpi=50)
plt.plot(x1,y1, color='yellow', linestyle='dashed', marker='o', label='linear plot')
plt.savefig("myfirstplot2.png",dpi=200)
df1.sort_values(by='mpg').plot(x='wt',y='mpg', kind='line')
df2 = df1.sort_values(by='mpg')
plt.plot(df2.wt, df2.mpg)
#plt.plot('wt','mpg', data=df2)
plt.scatter(x1,y2)
plt.scatter(df2.wt,df2.mpg)
plt.scatter(df1.gear, df1.mpg)
df1.gear.value_counts()
df1.plot(kind='scatter', x='gear',y='hp')
stockname = ['goog', 'ibm', 'tcs','hll']
stockvalues = [1000,2000,3000, 4000]
plt.bar(stockname,stockvalues, color='rg', width=0.75,align='center')
plt.barh(stockname,stockvalues, color='rg')
vc = df1.gear.value_counts()
print(vc)
vc.plot(kind='bar')
for index,values in enumerate(vc.values):
print(index,values)
plt.text(index,values,str(values))
agevalues = np.random.randint(0,101,size=100)
print(agevalues)
plt.hist([agevalues,agevalues*2], bins=10, rwidth=0.9,stacked=False,color=['r','g'])
plt.hist([agevalues,agevalues*2], bins=10, rwidth=0.9,stacked=True)
df1.plot(kind='hist', y='mpg')
df1.plot(kind='kde', y='mpg')
plt.style.use('ggplot')
v1 = list(range(100,200))
v1.append(10)
v1.append(300)
v1.append(400)
plt.boxplot(v1)
plt.show()
df1.hp.plot(kind='box')
df1[df1.hp > 300]
vc = df1.gear.value_counts()
print(vc)
plt.pie(x=vc.values, labels=vc.index, autopct='%.1f')
print()
plt.pie(x=vc.values, labels=vc.index, autopct='%.1f', explode=[0,0,0.25])
plt.legend(['abc','def','ghi'])
print()
sns.barplot([100,200,300],ci=95, estimator=np.mean)
from seaborn.utils import ci
sns.barplot(x='mpg', data=df1)
x = ci(df1.mpg)
print(x)
x = np.std(df1.mpg)
print(x)
x = np.mean(df1.mpg)
print(x)
sns.barplot([100,200,300,400,500])
sns.barplot(x='gear',y='mpg',data=df1)
sns.barplot(x='gear',y='mpg',data=df1, hue='cyl')
dp1 = df1.pivot_table(index='gear', columns='cyl', values='mpg',aggfunc='count')
print(dp1)
sns.scatterplot(x='gear',y='mpg',hue='cyl',data=df1)
sns.scatterplot(x='gear',y='cyl',data=df1)
sns.stripplot(x='gear',y='cyl',data=df1)
sns.swarmplot(x='gear',y='cyl',data=df1)
sns.regplot(data=df1, x='wt', y='mpg')
plt.title('regplot')
sns.lmplot(data=df1, x='wt', y='mpg')
sns.distplot(df1.mpg, bins=5, hist=True, kde=True, rug=True, hist_kws={'rwidth':0.5, 'color':'y'})
sns.boxplot(df1.mpg)
sns.boxplot(df1.mpg, orient='v')
sns.boxplot(data=df1,x='gear', y='mpg')
sns.boxplot(data=df1,x='gear', y='mpg', hue='am')
sns.boxenplot(data=df1,x='gear', y='mpg', hue='am')
sns.violinplot(data=df1,x='gear', y='mpg', hue='am')
sns.pairplot(df1[['mpg', 'gear','cyl']])
sns.jointplot(data=df1, x='gear', y='mpg',marginal_kws={'bins':10, 'kde':True,'color':'y'}, joint_kws={'color':'b'})
pd.set_option('display.width',1000)
#heat map
cmatrix = df1.corr()
cmatrix
plt.figure(figsize=(16,12))
sns.heatmap(cmatrix, annot=True)
fig, ax = plt.subplots(3,3, figsize=(10,12),dpi=100)
ax[0][0].set_title('00')
ax[0][1].set_title('01')
ax[1][0].set_title('10')
ax[1][1].set_title('11')
ax[0][0].set_xlabel('x00')
ax[0][1].set_xlabel('x01')
ax[1][0].set_xlabel('x10')
ax[1][1].set_xlabel('x11')
#print(type(ax[0][0]))
ax[0][0].scatter(df1.gear, df1.mpg)
ax[0][1].hist(df1.mpg)
ax[1][0].bar(df1.cyl, df1.mpg)
ax[1][1].scatter(df1.carb, df1.mpg)
plt.show()
print(ax)
print(fig)
ax[0][0].set_title('hello')
import plotly
plotly.offline.init_notebook_mode()
import plotly.express as px
import plotly.graph_objects as go
fig = px.box(data_frame=df2, y='mpg')
fig.show()
fig = px.scatter(data_frame=df1, x='cyl',y='mpg')
fig.show()
v1 = list(range(100,200))
v1.append(10)
v1.append(300)
v1.append(400)
fig = px.box(y=v1)
fig.show()
fig = px.histogram(data_frame=df1, x='mpg', nbins=10, title='histplot')
fig.show()
px.histogram(data_frame=df1, x='hp', nbins=10, title='histplot')